class Admin::SessionsController < Admin::ApplicationController
  layout false
  skip_before_action :check_admin

  def new
    redirect_to admin_root_url and return if session[:admin]
    Setting[:password]
    rescue Setting::SettingMissing then Setting[:password] = 'password'
  end

  def create
    if Setting[:password] == params[:password]
      session[:admin] = true
      redirect_to admin_root_url
    else
      render :new
    end
  end

  def destroy
    session.delete :admin
    redirect_to admin_sign_in_url
  end
end
